/**
 * 
 */
package org.bankabeule.ui.actions;

import org.bankabeule.ui.Activator;
import org.bankabeule.ui.utils.Logger;
import org.bankabeule.util.Utils;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;

/**
 * @author sdudoit
 *
 */
public class RemoveAction extends Action {

	/**
	 * Viewer
	 */
	private Viewer viewer;
	
	
	public RemoveAction(Viewer viewer) {
		super();
		setText("&Remove");
		setId(getClass().getCanonicalName());
		setImageDescriptor(Activator.getImageDescriptor("Remove.gif"));
		this.viewer = viewer;
	}
	
	
	@Override
	public void run() {
		try {
			StructuredSelection selection = (StructuredSelection) viewer.getSelection();
			for (Object object : selection.toList()) {
				Utils.delete((EObject) object);
			}
		} catch (Exception e) {
			Logger.log(e);
		}
	}
	
}
